<?php

namespace app\common\model\dealer;

use app\common\model\BaseModel;

/**
 * 分销商积分明细模型
 * Class Apply
 * @package app\common\model\dealer
 */
class CapitalPoints extends BaseModel
{
    protected $name = 'dealer_capital_points';

    /**
     * 分销商积分明细
     * @param $data
     */
    public static function add($data)
    {
        $model = new static;
        $model->save(array_merge($data, [
            'wxapp_id' => $model::$wxapp_id
        ]));
    }

    /**
     * 计算本月积分数
     * @param $user_id
     * @return float|int|string
     */
    public static function getMonthPoints($user_id)
    {
        $startTime = strtotime(date("Y-m-01", strtotime(date("Y-m-d"))));
        return self::where('create_time', '>=', $startTime)->where('user_id', '=', $user_id)->sum('points_num');
    }

}